import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_app/utils/windowUtil.dart';
import 'package:flutter_app/bean/ChatItem.dart';

class Conversation extends StatefulWidget   {
  @override
  State<Conversation> createState() => _ConversationState();
}

class _ConversationState extends State<Conversation> with AutomaticKeepAliveClientMixin{
  List<ChatItem> list;
  @override
  void initState() {
    super.initState();
    createchatitem();
  }

  String _bodyStr = "显示菜单内容";
  @override
  bool get wantKeepAlive => true;
  @override
  Widget build(BuildContext context) {
    SystemChrome.setSystemUIOverlayStyle(SystemUiOverlayStyle.dark);
    return new Scaffold(
        backgroundColor: Color(0xffffffff),
        appBar: new AppBar(
          //brightness: Brightness.light,

          elevation: 0.0,
          backgroundColor: Color(0xffffffff),
          title: new Text(
            "聊天",
            style: TextStyle(
                color: Color(0xff000000),
                fontSize: 20.0,
                fontWeight: FontWeight.bold),
          ),
          actions: <Widget>[
            new PopupMenuButton(
                onSelected: (String value) {
                  setState(() {
                    _bodyStr = value;
                  });
                },
                child: Container(
                  width: 50.0,
                  height: 50.0,
                  padding: EdgeInsets.all(15.0),
                  child: Image.asset(
                    "images/plus.png",
                    width: 20.0,
                    height: 20.0,
                  ),
                ),
                itemBuilder: (BuildContext context) => <PopupMenuItem<String>>[
                      new PopupMenuItem(
                          value: "选项一的内容",
                          child: Row(
                            children: <Widget>[
                              Image.asset(
                                "images/chat.png",
                                width: 20.0,
                                height: 20.0,
                                fit: BoxFit.fill,
                              ),
                              Text("发起群聊")
                            ],
                          )),
                      new PopupMenuItem(
                          value: "选项二的内容",
                          child: Row(
                            children: <Widget>[
                              Image.asset(
                                "images/addf.png",
                                width: 20.0,
                                height: 20.0,
                                fit: BoxFit.fill,
                              ),
                              Text("添加朋友")
                            ],
                          )),
                      new PopupMenuItem(
                          value: "选项二的内容",
                          child: Row(
                            children: <Widget>[
                              Image.asset(
                                "images/qr.png",
                                width: 20.0,
                                height: 20.0,
                                fit: BoxFit.fill,
                              ),
                              Text("扫一扫")
                            ],
                          )),
                      new PopupMenuItem(
                          value: "选项二的内容",
                          child: Row(
                            children: <Widget>[
                              Image.asset(
                                "images/ewm.png",
                                width: 20.0,
                                height: 20.0,
                                fit: BoxFit.fill,
                              ),
                              Text("二维码")
                            ],
                          )),
                    ])
          ],
        ),
        body: new CustomScrollView(
          slivers: <Widget>[
            SliverToBoxAdapter(
              child: Column(
                children: <Widget>[
                  Container(
                    color: Color(0xffffffff),
                    margin: EdgeInsets.only(left: 13.0, right: 13.0, top: 20.0),
                    child: Row(
                      mainAxisAlignment: MainAxisAlignment.spaceBetween,
                      children: <Widget>[
                        Column(
                          children: <Widget>[
                            Image.asset(
                              "images/myfriend.png",
                              width: 60.0,
                              height: 50.0,
                              fit: BoxFit.fitHeight,
                            ),
                            SizedBox(
                              height: 5.0,
                            ),
                            Text("我的好友"),
                          ],
                        ),
                        Column(
                          children: <Widget>[
                            Image.asset(
                              "images/mygroup.png",
                              width: 60.0,
                              height: 50.0,
                              fit: BoxFit.fitHeight,
                            ),
                            SizedBox(
                              height: 5.0,
                            ),
                            Text("我的群聊"),
                          ],
                        ),
                        Column(
                          children: <Widget>[
                            Image.asset(
                              "images/info.png",
                              width: 60.0,
                              height: 50.0,
                              fit: BoxFit.fitHeight,
                            ),
                            SizedBox(
                              height: 5.0,
                            ),
                            Text("系统消息"),
                          ],
                        ),
                        Column(
                          children: <Widget>[
                            Image.asset(
                              "images/newfriend.png",
                              width: 60.0,
                              height: 50.0,
                              fit: BoxFit.fitHeight,
                            ),
                            SizedBox(
                              height: 5.0,
                            ),
                            Text("新的朋友"),
                          ],
                        ),
                      ],
                    ),
                  ),
                  Container(
                    margin: EdgeInsets.only(left: 13.0, right: 13.0, top: 25.0),
                    height: 100.0,
                    child: Image.asset("images/conversation.png"),
                  ),
                  Container(
                    margin: EdgeInsets.only(left: 13.0, right: 13.0, top: 20.0),
                    child: Row(
                      crossAxisAlignment: CrossAxisAlignment.end,
                      children: <Widget>[
                        Text(
                          "我的群聊",
                          style: TextStyle(
                              color: Color(0xff000000),
                              fontSize: 20.0,
                              fontWeight: FontWeight.bold),
                        ),
                        Container(
                          margin: EdgeInsets.only(left: 20.0, bottom: 1.0),
                          child: Text(
                            "群聊也能挖矿",
                            style: TextStyle(color: Colors.grey),
                          ),
                        )
                      ],
                    ),
                  ),
                ],
              ),
            ),
            SliverList(
              delegate: SliverChildBuilderDelegate((context, index) {
                return chatitem(context, index);
                //  return chat1();
              }, childCount: list.length),
            ),
          ],
        ));
  }

  Widget chat1() {
    return Text("1");
  }

  Widget chatitem(c, index) {
    return Container(
      margin: EdgeInsets.only(left: 13.0, right: 13.0, top: 20.0),
      child: Row(
        children: <Widget>[
          Image.asset(
            list[index].url,
            width: 60.0,
            height: 60.0,
            fit: BoxFit.cover,
          ),
          SizedBox(
            width: 10.0,
          ),
          Container(
            child: Column(
              children: <Widget>[
                Container(
                  width: windowUtil.width - 26 - 60 - 10,
                  child: Row(
                    children: <Widget>[
                      SizedBox(
                        width: 10.0,
                      ),
                      Expanded(
                        child: Column(
                          crossAxisAlignment: CrossAxisAlignment.start,
                          children: <Widget>[
                            Text(
                              list[index].name,
                              style: TextStyle(fontSize: 16.0),
                            ),
                            SizedBox(
                              height: 10.0,
                            ),
                            Text(
                              list[index].content,
                              style: TextStyle(color: Colors.grey),
                            )
                          ],
                        ),
                      ),
                      Container(
                        width: 50.0,
                        child: Text(
                          list[index].time,
                          style: TextStyle(color: Colors.grey),
                        ),
                      ),
                    ],
                  ),
                ),
                Container(
                  height: 1.0,
                  color: Colors.grey,
                  margin: EdgeInsets.only(top: 10.0),
                )
              ],
            ),
          )
        ],
      ),
    );
  }

  List<ChatItem> createchatitem() {
    list = List();

    list.add(new ChatItem("小二狗", "images/fruit.jpg", "收到一个红包", "昨天"));
    list.add(new ChatItem("小二狗", "images/fruit.jpg", "收到一个红包", "昨天"));
    list.add(new ChatItem("小二狗", "images/fruit.jpg", "收到一个红包", "昨天"));
  }
}
